package org.itboys.member;

import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.itboys.commons.CommonConstants;
import org.itboys.commons.utils.ajax.AjaxUtils;
import org.itboys.framework.query.JsonPageUtils;
import org.itboys.framework.spring.controller.BaseController;
import org.itboys.fuzion.entity.WithdrawsRecords;
import org.itboys.fuzion.service.WithdrawsRecordsService;
import org.itboys.mongodb.utils.page.Page;
import org.itboys.mongodb.utils.query.QueryParamUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

/**
 * 提现
 * @author weisky
 *
 * 2016年4月19日
 */
@RestController 
@RequestMapping("/withdrawsRecords") 
public class WithdrawsRecordsController extends BaseController{

	@Autowired
	private WithdrawsRecordsService withdrawsRecordsService;
	
	@RequestMapping("/toListVM")
	public ModelAndView toListVM(HttpServletRequest request, HttpServletResponse response) {
		return new ModelAndView("/member/withdraws-records");
	}
	
	@RequestMapping("/list")
	public void list(HttpServletRequest request, HttpServletResponse response){
		Map<String, Object> param = QueryParamUtils.builderQueryMap(request);
		Page<WithdrawsRecords> page = withdrawsRecordsService.listByPage(param, request);
		JsonPageUtils.renderJsonPage(page.getTotalPages(), page.getData(), response);
	} 
	
	/**
	 * 修改提现审核状态
	 * @param member
	 * @param request
	 * @param response
	 */
	@RequestMapping("/update/type")
	public void update(Long id, 
			HttpServletRequest request, HttpServletResponse response){
		
		boolean result = withdrawsRecordsService.checkWithdrawsRecords(id);
		if(result){
			AjaxUtils.renderText(response, CommonConstants.SUCCESS);
		}else{
			AjaxUtils.renderText(response, CommonConstants.FAIL);
		}
	}
}
